const { knex, TABLE_NAME } = require('./db');
const { logger } = require('../utils');

knex.schema.hasTable(TABLE_NAME.contract).then((exists) => {
  if (!exists) {
    return knex.schema.createTable(TABLE_NAME.contract, (t) => {
      t.charset('utf8');
      t.uuid('id').primary();
      // 渠道控件字段
      t.string('monthlyPay', 100);
      t.timestamp('contractStartTime').defaultTo(knex.fn.now());
      t.timestamp('contractEndTime').defaultTo(knex.fn.now());
      t.integer('CreateOn', 20);
      t.string('CustomData');
      t.string('DeadLine');
      t.json('FlowApproverInfos');
      t.string('FlowId');
      t.string('FlowMessage');
      t.string('FlowName');
      t.string('FlowStatus');
      t.string('FlowType');
      t.string('UserId');
      t.integer('SignBeanTag');
      t.string('organizationId');
    });
  }
})
  .catch((err) => {
    logger.error({
      message: err.message,
      stack: err.stack,
      Action: 'contract/createTable',
    });
    console.error(err);
  });

